#include "widget.h"
#include "ui_widget.h"

#include <QDebug>
#include <QListWidget>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    QListWidget* list = new QListWidget(this);
    list->resize(250, 350);
    list->move(320, 30);
    list->setViewMode(QListView::ListMode);
    list->setAlternatingRowColors(true);

    // 通过字符串方式设置每一项
//    list->addItem("篮球");
//    list->addItem("排球");

    // 通过对象方式设置每一项
    QListWidgetItem* item1 = new QListWidgetItem;
    item1->setText("乒乓球");
    item1->setIcon(QIcon(":/images/icon-test"));
    item1->setTextAlignment(Qt::AlignCenter);
    list->addItem(item1);

    QListWidgetItem* item2 = new QListWidgetItem;
    item2->setText("羽毛球");
    item2->setIcon(QIcon(":/images/icon-test_1"));
    item2->setTextAlignment(Qt::AlignCenter);
    list->addItem(item2);

    QListWidgetItem* item3 = new QListWidgetItem;
    item3->setText("棒球");
    item3->setIcon(QIcon(":/images/qiatongtouxiang"));
    item3->setTextAlignment(Qt::AlignCenter);
    list->addItem(item3);

    QListWidgetItem* item4 = new QListWidgetItem;
    item4->setText("橄榄球");
    item4->setIcon(QIcon(":/images/user__easyico_1"));
    item4->setTextAlignment(Qt::AlignCenter);
    list->insertItem(1, item4);


}

Widget::~Widget()
{
    delete ui;
}

// 点击list中的任一项某一项触发
void Widget::on_listWidget_itemClicked(QListWidgetItem *item)
{
//    qDebug() << item->text();
//    item->setText("abc");
}

// 当前选项的文本发生改变时触发
void Widget::on_listWidget_itemChanged(QListWidgetItem *item)
{
    qDebug() << "itemChanged" << item->text();
}

void Widget::on_listWidget_itemActivated(QListWidgetItem *item)
{
    qDebug() << "itemActivated" << item->text();
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    qDebug() << "current" << current->text();
    qDebug() << "prev" << previous->text();
}
